<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="1500"
			   destroy-on-close @closed="$emit('closed')" align-center :close-on-click-modal="false"
			   :close-on-press-escape="mode != 'show' ? false : true">
		<el-form :model="form" :rules="rules" :disabled="mode=='show'" label-width="110" ref="dialogForm">
			<el-row :gutter="1">
				<el-col :span="6">
					<el-form-item label="任务名称" prop="title">
						<el-input v-model="form.title" placeholder="请输入任务名称" clearable readonly></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6">
					<el-form-item label="跟进状态" prop="status">
						<el-select v-model="form.status" placeholder="选择跟进状态" filterable>
							<el-option v-for="item in follow_status" :key="item.value" :label="item.name" :value="Number(item.value)"/>
						</el-select>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="1">
				<el-col :span="24">
					<sc-editor  v-model="form.content" placeholder="请输入" :height="600"></sc-editor>
				</el-col>
			</el-row>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">{{$t('all.cancel')}}</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit(1)">{{$t('all.save')}}</el-button>
		</template>
	</el-dialog>
</template>

<script>
import { defineAsyncComponent } from 'vue';
const scEditor = defineAsyncComponent(() => import('@/components/scEditor'));
export default {
	components: {
		scEditor
	},
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '新增任务跟进',
				edit: '新增任务跟进',
				show: '新增任务跟进',
			},
			visible: false,
			isSaveing: false,
			form: {
				id: "",
				title:'',
				content:'',
				status:10
			},
			stage: false,
			rules: {
				content: [
					{required: true, message: '请输入跟进内容'}
				],
			},
			dialog: {

			},
			follow_status:[]
		}
	},
	mounted() {
		this.getContract()
	},
	methods: {
		/**获取数据字典*/
		async getContract() {
			var res = await this.$API.common.getDictData.get({
				type: 'follow_status'
			});
			this.follow_status = res.data.follow_status
		},
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		//表单提交方法
		submit(e) {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res = [];
					res = await this.$API.task.addFollow.post(this.form);
					this.isSaveing = false;
					if (res != '') {
						if (res.code == 1) {
							this.visible = false;
							if (e == 1) {
								this.$emit('success', this.form, this.mode, e)
								this.$message.success(this.$t('all.yes'))
							} else {
								this.$emit('success', res.data, 'check')
							}
						} else {
							this.$alert(res.message,this.$t('all.prompt'), {type: "error"});
						}
					}
				}
			})
		},
		//表单注入数据
		async setData(data) {
			this.form.id = data.id
			this.form.title = data.title
		},
	}
}
</script>

<style>
</style>
